<template>
    <div>
        <NavBar>
            <div class="el-icon-arrow-left" slot="left" @click="onClickLeft()"></div>
            <div class="center" slot="center">选择地址</div>
        </NavBar>
        <van-address-list class="userList" v-model="chosenAddressId" :list="list" :disabled-list="disabledList"
            disabled-text="以下地址超出配送范围" default-tag-text="默认" @add="onAdd" @edit="onEdit" @select="onBack" />

    </div>
</template>

<script>
import NavBar from "../../components/NavBar.vue";
import { ContactCard, Toast } from 'vant';
import { deliveryAddressList } from "../../api/reques";
export default {
    components: { NavBar },
    data() {
        return {
            chosenAddressId: '1',
            list: [],
            disabledList: [
                {
                    id: '3',
                    name: '王五',
                    tel: '1320000000',
                    address: '浙江省杭州市滨江区江南大道 15 号',
                },
            ],
        };
    },
    mounted(){
        deliveryAddressList().then((res)=>{
            console.log(res.data);
            this.list = res.data.map((item,index)=>{
                return {
                    id:item.id,
                    name:item.name,
                    address:item.address,
                    tel:item.phone,
                    // isDefault:true
                }
            })
            // this.list = res.data
            console.log( 111111111, this.list);
        })
    },
    methods: {
        onClickLeft() {
            this.$router.back()
        },
        onAdd() {
            this.$router.push("/address")
        },
        onEdit(item, index) {
            Toast('编辑地址:' + index);
        },
        // confirmOrder/3284
        onBack(item,index) {
            console.log(item);
            const a = JSON.stringify(item)
            console.log(a);
            localStorage.setItem("addressDetail",JSON.stringify(item))
            this.$router.back()
        }
    },
};
</script>

<style>
.userList {
    margin-top: 35px;
}
</style>
